package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by Administrator on 2016/7/20.
 */
public abstract class CommonRecyclerViewAdapter<T> extends RecyclerView.Adapter<CommonHolder> {

    private Context mContext;
    private List<T> mDatas;
    private int mItemLayoutId;

    public CommonRecyclerViewAdapter(Context context, List<T> datas, int itemLayoutId) {
        mContext = context;
        mDatas = datas;
        mItemLayoutId = itemLayoutId;
    }

    @Override
    public CommonHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(mItemLayoutId, parent, false);
        return new CommonHolder(view);
    }

    @Override
    public void onBindViewHolder(CommonHolder holder, int position) {
        //模板设计模式
        bindData(holder, position, mDatas.get(position));
    }


    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    public abstract void bindData(CommonHolder holder, int position, T bean);
}
